import javaService from '@/Yapi/java/javaHttp'

/**
 * 字段配置API
 */

// 根据表单ID获取所有字段配置
export function getFieldListByFormId(formId) {
  return javaService({
    url: `${process.env.VUE_APP_DEV_JAVA_BASE_HOST}/form/field/list/${formId}`,
    method: 'get'
  })
}

// 创建字段配置
export function createFieldConfig(data) {
  return javaService({
    url: `${process.env.VUE_APP_DEV_JAVA_BASE_HOST}/form/field`,
    method: 'post',
    data
  })
}

// 更新字段配置
export function updateFieldConfig(id, data) {
  return javaService({
    url: `${process.env.VUE_APP_DEV_JAVA_BASE_HOST}/form/field/${id}`,
    method: 'put',
    data
  })
}

// 删除字段配置
export function deleteFieldConfig(id) {
  return javaService({
    url: `${process.env.VUE_APP_DEV_JAVA_BASE_HOST}/form/field/${id}`,
    method: 'delete'
  })
}

// ==================== 校验规则相关 ====================

// 添加字段校验规则
export function addValidationRule(fieldId, data) {
  return javaService({
    url: `${process.env.VUE_APP_DEV_JAVA_BASE_HOST}/form/field/${fieldId}/validation-rule`,
    method: 'post',
    data
  })
}

// 获取字段的所有校验规则
export function getValidationRules(fieldId) {
  return javaService({
    url: `${process.env.VUE_APP_DEV_JAVA_BASE_HOST}/form/field/${fieldId}/validation-rules`,
    method: 'get'
  })
}

// 更新校验规则
export function updateValidationRule(ruleId, data) {
  return javaService({
    url: `${process.env.VUE_APP_DEV_JAVA_BASE_HOST}/form/field/validation-rule/${ruleId}`,
    method: 'put',
    data
  })
}

// 删除校验规则
export function deleteValidationRule(ruleId) {
  return javaService({
    url: `${process.env.VUE_APP_DEV_JAVA_BASE_HOST}/form/field/validation-rule/${ruleId}`,
    method: 'delete'
  })
}

// ==================== 颜色规则相关 ====================

// 添加字段颜色规则
export function addColorRule(fieldId, data) {
  return javaService({
    url: `${process.env.VUE_APP_DEV_JAVA_BASE_HOST}/form/field/${fieldId}/color-rule`,
    method: 'post',
    data
  })
}

// 获取字段的所有颜色规则
export function getColorRules(fieldId) {
  return javaService({
    url: `${process.env.VUE_APP_DEV_JAVA_BASE_HOST}/form/field/${fieldId}/color-rules`,
    method: 'get'
  })
}

// 更新颜色规则
export function updateColorRule(ruleId, data) {
  return javaService({
    url: `${process.env.VUE_APP_DEV_JAVA_BASE_HOST}/form/field/color-rule/${ruleId}`,
    method: 'put',
    data
  })
}

// 删除颜色规则
export function deleteColorRule(ruleId) {
  return javaService({
    url: `${process.env.VUE_APP_DEV_JAVA_BASE_HOST}/form/field/color-rule/${ruleId}`,
    method: 'delete'
  })
}
